"""
包含全局可以获取的信息
"""
import threading
from client_resource.resource_manager import ResourceManager
from query_analyse.query_analyse_manager import QueryAnalyseManager
from retrieve.retrieve_manager import RetrieveManager
from merge.merge_manager import MergeManager
from rank.rank_manager import RankManager
from adjust.adjust_manager import AdjustManager
from strategy.strategy_manager import StrategyManager
from rank.feature_manager import FeatureManager

class GlobalResource:
    _instance_lock = threading.Lock()

    def __init__(self, all_config):
        """
        单例模式,保证所有manager都存储进来了
        """
        # 初始化资源类
        self.resource_manager = ResourceManager(all_config["resource_service"])
        if not self.resource_manager:
            print("resource_manager init failed")

        # 初始化query analyse
        self.query_analyse_manager = QueryAnalyseManager(all_config["query_analyse_service"])
        if not self.query_analyse_manager:
            print("query_analyse_manager init failed")

        # 初始化retrieve
        self.retrieve_manager = RetrieveManager(all_config["retrieve_service"])
        if not self.retrieve_manager:
            print("retrieve_manager init failed")

        # 初始化merge
        self.merge_manager = MergeManager(all_config["merge_service"])
        if not self.merge_manager:
            print("merge_manager init failed")

        # 初始化rank
        self.rank_manager = RankManager(all_config["rank_service"])
        if not self.rank_manager:
            print("rank_manager init failed")

        # 初始化adjust
        self.adjust_manager = AdjustManager(all_config["adjust_service"])
        if not self.adjust_manager:
            print("adjust_manager init failed")

        # 初始化strategy
        self.strategy_manager = StrategyManager(all_config["strategy"])
        if not self.strategy_manager:
            print("strategy_manager init failed")

        # 初始化所有feature
        self.feature_manager = FeatureManager(all_config["feature"])
        if not self.feature_manager:
            print("feature_manager init failed")

    @classmethod
    def instance(cls, *args, **kwargs):
        with GlobalResource._instance_lock:
            if not hasattr(GlobalResource, "_instance"):
                GlobalResource._instance = GlobalResource(*args, **kwargs)
        return GlobalResource._instance
